{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "d1f05540",
   "metadata": {},
   "source": [
    "# geomPie()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "34f2ff62",
   "metadata": {},
   "source": [
    "A pie chart is a circular statistical graphic, which is divided into slices to illustrate numerical proportion."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "36044c48",
   "metadata": {},
   "source": [
    "1. [Default presentation](#1.-Default-presentation)\n",
    "\n",
    "    1.1. [Basic pie chart](#1.1.-Basic-pie-chart)\n",
    "    \n",
    "    1.2. [Improve appearance](#1.2.-Improve-appearance)   \n",
    "    \n",
    "    1.3. [Adding labels to pie sectors](#1.3.-Adding-labels-to-pie-sectors) \n",
    "    \n",
    "    1.4. [Use \"count2d\" statistical transformation](#1.4.-Use-\"count2d\"-statistical-transformation)\n",
    "      \n",
    "        \n",
    "2. [Pie size depending on data](#2.-Pie-size-depending-on-data)\n",
    "\n",
    "      \n",
    "3. [Explode](#3.-Explode)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "faa30d88",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"Isk30V\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"library\">\n",
       "       if(!window.letsPlotCallQueue) {\n",
       "           window.letsPlotCallQueue = [];\n",
       "       }; \n",
       "       window.letsPlotCall = function(f) {\n",
       "           window.letsPlotCallQueue.push(f);\n",
       "       };\n",
       "       (function() {\n",
       "           var script = document.createElement(\"script\");\n",
       "           script.type = \"text/javascript\";\n",
       "           script.src = \"https://cdn.jsdelivr.net/gh/JetBrains/lets-plot@v3.2.0/js-package/distr/lets-plot.min.js\";\n",
       "           script.onload = function() {\n",
       "               window.letsPlotCall = function(f) {f();};\n",
       "               window.letsPlotCallQueue.forEach(function(f) {f();});\n",
       "               window.letsPlotCallQueue = [];\n",
       "               \n",
       "               \n",
       "           };\n",
       "           script.onerror = function(event) {\n",
       "               window.letsPlotCall = function(f) {};\n",
       "               window.letsPlotCallQueue = [];\n",
       "               var div = document.createElement(\"div\");\n",
       "               div.style.color = 'darkred';\n",
       "               div.textContent = 'Error loading Lets-Plot JS';\n",
       "               document.getElementById(\"Isk30V\").appendChild(div);\n",
       "           };\n",
       "           var e = document.getElementById(\"Isk30V\");\n",
       "           e.appendChild(script);\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "            <div id=\"kotlin_out_0\"></div>\n",
       "            <script type=\"text/javascript\">\n",
       "                            if(!window.kotlinQueues) {\n",
       "                window.kotlinQueues = {};\n",
       "            }\n",
       "            if(!window.kotlinQueues[\"DataFrame\"]) {\n",
       "                var resQueue = [];\n",
       "                window.kotlinQueues[\"DataFrame\"] = resQueue;\n",
       "                window[\"call_DataFrame\"] = function(f) {\n",
       "                    resQueue.push(f);\n",
       "                }\n",
       "            }\n",
       "            (function (){\n",
       "                var modifiers = [(function(script) {\n",
       "    script.src = \"https://cdn.jsdelivr.net/gh/Kotlin/dataframe@3db46ccccaa1291c0627307d64133317f545e6ae/core/src/main/resources/init.js\"\n",
       "    script.type = \"text/javascript\";\n",
       "})];\n",
       "                var e = document.getElementById(\"kotlin_out_0\");\n",
       "                modifiers.forEach(function (gen) {\n",
       "                    var script = document.createElement(\"script\");\n",
       "                    gen(script)\n",
       "                    script.addEventListener(\"load\", function() {\n",
       "                        window[\"call_DataFrame\"] = function(f) {f();};\n",
       "                        window.kotlinQueues[\"DataFrame\"].forEach(function(f) {f();});\n",
       "                        window.kotlinQueues[\"DataFrame\"] = [];\n",
       "                    }, false);\n",
       "                    script.addEventListener(\"error\", function() {\n",
       "                        window[\"call_DataFrame\"] = function(f) {};\n",
       "                        window.kotlinQueues[\"DataFrame\"] = [];\n",
       "                        var div = document.createElement(\"div\");\n",
       "                        div.style.color = 'darkred';\n",
       "                        div.textContent = 'Error loading resource DataFrame';\n",
       "                        document.getElementById(\"kotlin_out_0\").appendChild(div);\n",
       "                    }, false);\n",
       "                    \n",
       "                    e.appendChild(script);\n",
       "                });\n",
       "            })();\n",
       "            </script>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "                <style>\n",
       "                :root {\n",
       "    --background: #fff;\n",
       "    --background-odd: #f5f5f5;\n",
       "    --background-hover: #d9edfd;\n",
       "    --header-text-color: #474747;\n",
       "    --text-color: #848484;\n",
       "    --text-color-dark: #000;\n",
       "    --text-color-medium: #737373;\n",
       "    --text-color-pale: #b3b3b3;\n",
       "    --inner-border-color: #aaa;\n",
       "    --bold-border-color: #000;\n",
       "    --link-color: #296eaa;\n",
       "    --link-color-pale: #296eaa;\n",
       "    --link-hover: #1a466c;\n",
       "}\n",
       "\n",
       ":root[theme=\"dark\"], :root [data-jp-theme-light=\"false\"], .dataframe_dark{\n",
       "    --background: #303030;\n",
       "    --background-odd: #3c3c3c;\n",
       "    --background-hover: #464646;\n",
       "    --header-text-color: #dddddd;\n",
       "    --text-color: #b3b3b3;\n",
       "    --text-color-dark: #dddddd;\n",
       "    --text-color-medium: #b2b2b2;\n",
       "    --text-color-pale: #737373;\n",
       "    --inner-border-color: #707070;\n",
       "    --bold-border-color: #777777;\n",
       "    --link-color: #008dc0;\n",
       "    --link-color-pale: #97e1fb;\n",
       "    --link-hover: #00688e;\n",
       "}\n",
       "\n",
       "p.dataframe_description {\n",
       "    color: var(--text-color-dark);\n",
       "}\n",
       "\n",
       "table.dataframe {\n",
       "    font-family: \"Helvetica Neue\", Helvetica, Arial, sans-serif;\n",
       "    font-size: 12px;\n",
       "    background-color: var(--background);\n",
       "    color: var(--text-color-dark);\n",
       "    border: none;\n",
       "    border-collapse: collapse;\n",
       "}\n",
       "\n",
       "table.dataframe th, td {\n",
       "    padding: 6px;\n",
       "    border: 1px solid transparent;\n",
       "    text-align: left;\n",
       "}\n",
       "\n",
       "table.dataframe th {\n",
       "    background-color: var(--background);\n",
       "    color: var(--header-text-color);\n",
       "}\n",
       "\n",
       "table.dataframe td {\n",
       "    vertical-align: top;\n",
       "}\n",
       "\n",
       "table.dataframe th.bottomBorder {\n",
       "    border-bottom-color: var(--bold-border-color);\n",
       "}\n",
       "\n",
       "table.dataframe tbody > tr:nth-child(odd) {\n",
       "    background: var(--background-odd);\n",
       "}\n",
       "\n",
       "table.dataframe tbody > tr:nth-child(even) {\n",
       "    background: var(--background);\n",
       "}\n",
       "\n",
       "table.dataframe tbody > tr:hover {\n",
       "    background: var(--background-hover);\n",
       "}\n",
       "\n",
       "table.dataframe a {\n",
       "    cursor: pointer;\n",
       "    color: var(--link-color);\n",
       "    text-decoration: none;\n",
       "}\n",
       "\n",
       "table.dataframe tr:hover > td a {\n",
       "    color: var(--link-color-pale);\n",
       "}\n",
       "\n",
       "table.dataframe a:hover {\n",
       "    color: var(--link-hover);\n",
       "    text-decoration: underline;\n",
       "}\n",
       "\n",
       "table.dataframe img {\n",
       "    max-width: fit-content;\n",
       "}\n",
       "\n",
       "table.dataframe th.complex {\n",
       "    background-color: var(--background);\n",
       "    border: 1px solid var(--background);\n",
       "}\n",
       "\n",
       "table.dataframe .leftBorder {\n",
       "    border-left-color: var(--inner-border-color);\n",
       "}\n",
       "\n",
       "table.dataframe .rightBorder {\n",
       "    border-right-color: var(--inner-border-color);\n",
       "}\n",
       "\n",
       "table.dataframe .rightAlign {\n",
       "    text-align: right;\n",
       "}\n",
       "\n",
       "table.dataframe .expanderSvg {\n",
       "    width: 8px;\n",
       "    height: 8px;\n",
       "    margin-right: 3px;\n",
       "}\n",
       "\n",
       "table.dataframe .expander {\n",
       "    display: flex;\n",
       "    align-items: center;\n",
       "}\n",
       "\n",
       "/* formatting */\n",
       "\n",
       "table.dataframe .null {\n",
       "    color: var(--text-color-pale);\n",
       "}\n",
       "\n",
       "table.dataframe .structural {\n",
       "    color: var(--text-color-medium);\n",
       "    font-weight: bold;\n",
       "}\n",
       "\n",
       "table.dataframe .dataFrameCaption {\n",
       "    font-weight: bold;\n",
       "}\n",
       "\n",
       "table.dataframe .numbers {\n",
       "    color: var(--text-color-dark);\n",
       "}\n",
       "\n",
       "table.dataframe td:hover .formatted .structural, .null {\n",
       "    color: var(--text-color-dark);\n",
       "}\n",
       "\n",
       "table.dataframe tr:hover .formatted .structural, .null {\n",
       "    color: var(--text-color-dark);\n",
       "}\n",
       "\n",
       "\n",
       "                </style>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "%useLatestDescriptors\n",
    "%use lets-plot\n",
    "%use dataframe"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "8786a3e7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Lets-Plot Kotlin API v.4.4.1. Frontend: Notebook with dynamically loaded JS. Lets-Plot JS v.3.2.0."
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "LetsPlot.getInfo()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "444122dd",
   "metadata": {},
   "outputs": [],
   "source": [
    "val blankTheme = theme(line=elementBlank(), axis=elementBlank())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "42063da2",
   "metadata": {},
   "outputs": [],
   "source": [
    "val (w, h) = 400 to 250\n",
    "\n",
    "val data = mapOf(\n",
    "    \"name\" to listOf('a', 'b', 'c', 'd', 'b'),\n",
    "    \"value\" to listOf(40, 90, 10,  50,  20)\n",
    ")\n",
    "\n",
    "val p = letsPlot(data) + ggsize(w,h)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d3496545",
   "metadata": {},
   "source": [
    "## 1. Default presentation"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e670679c",
   "metadata": {},
   "source": [
    "### 1.1. Basic pie chart"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ae3a2237",
   "metadata": {},
   "source": [
    "Use \"identity\" statistical transformation to leave the data unchanged."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "8e854954",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"VG87pc\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"mapping\":{\n",
       "},\n",
       "\"data\":{\n",
       "\"name\":[\"a\",\"b\",\"c\",\"d\",\"b\"],\n",
       "\"value\":[40.0,90.0,10.0,50.0,20.0]\n",
       "},\n",
       "\"ggsize\":{\n",
       "\"width\":400.0,\n",
       "\"height\":250.0\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"slice\":\"value\",\n",
       "\"fill\":\"name\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"pie\",\n",
       "\"data\":{\n",
       "}\n",
       "}]\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"VG87pc\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();    \n",
       "   </script>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p + geomPie(stat = Stat.identity) { slice = \"value\"; fill = \"name\" }"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a6468831",
   "metadata": {},
   "source": [
    "### 1.2. Improve appearance"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9b23c4df",
   "metadata": {},
   "source": [
    "- add stroke (`stroke` and `strokeColor`)\n",
    "- make the pie bigger (`size`)\n",
    "- add hole to draw donut-like chart (`hole`)\n",
    "- use blank theme (remove axis and grid)\n",
    "- use better colors"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "f9fbaa2c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"E4BSWT\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"mapping\":{\n",
       "},\n",
       "\"data\":{\n",
       "\"name\":[\"a\",\"b\",\"c\",\"d\",\"b\"],\n",
       "\"value\":[40.0,90.0,10.0,50.0,20.0]\n",
       "},\n",
       "\"ggsize\":{\n",
       "\"width\":400.0,\n",
       "\"height\":250.0\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"fill\",\n",
       "\"scale_mapper_kind\":\"color_brewer\",\n",
       "\"palette\":\"Set1\"\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"hole\":0.5,\n",
       "\"mapping\":{\n",
       "\"slice\":\"value\",\n",
       "\"fill\":\"name\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":20.0,\n",
       "\"stroke_color\":\"white\",\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"pie\",\n",
       "\"stroke\":1.0,\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"theme\":{\n",
       "\"axis\":{\n",
       "\"blank\":true\n",
       "},\n",
       "\"line\":{\n",
       "\"blank\":true\n",
       "}\n",
       "}\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"E4BSWT\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();    \n",
       "   </script>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p +\n",
    "    geomPie(stat = Stat.identity,\n",
    "            size = 20, stroke = 1, strokeColor = \"white\", hole = 0.5) { slice = \"value\"; fill = \"name\" } +\n",
    "    blankTheme + \n",
    "    scaleFillBrewer(palette = \"Set1\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a760b099",
   "metadata": {},
   "source": [
    "### 1.3. Adding labels to pie sectors"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "46617ca9",
   "metadata": {},
   "source": [
    "Let's label the sectors with their names - configure annotations via `layerLabels()` function: "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "1ffd0e96",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"PYG4CB\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"mapping\":{\n",
       "},\n",
       "\"data\":{\n",
       "\"name\":[\"a\",\"b\",\"c\",\"d\",\"b\"],\n",
       "\"value\":[40.0,90.0,10.0,50.0,20.0]\n",
       "},\n",
       "\"ggsize\":{\n",
       "\"width\":400.0,\n",
       "\"height\":250.0\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"fill\",\n",
       "\"scale_mapper_kind\":\"color_brewer\",\n",
       "\"palette\":\"Set1\"\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"hole\":0.5,\n",
       "\"mapping\":{\n",
       "\"slice\":\"value\",\n",
       "\"fill\":\"name\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":20.0,\n",
       "\"stroke_color\":\"white\",\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"pie\",\n",
       "\"stroke\":1.0,\n",
       "\"labels\":{\n",
       "\"lines\":[\"@name\"],\n",
       "\"annotation_size\":16\n",
       "},\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"theme\":{\n",
       "\"axis\":{\n",
       "\"blank\":true\n",
       "},\n",
       "\"line\":{\n",
       "\"blank\":true\n",
       "},\n",
       "\"legend_position\":\"none\"\n",
       "}\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"PYG4CB\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();    \n",
       "   </script>"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p + \n",
    "    geomPie(\n",
    "        stat = Stat.identity,\n",
    "        size = 20, stroke = 1, strokeColor = \"white\", hole = 0.5,\n",
    "        labels = layerLabels().line(\"@name\").size(16)\n",
    "    ) { slice = \"value\"; fill = \"name\" } +\n",
    "    blankTheme + \n",
    "    theme().legendPositionNone() +\n",
    "    scaleFillBrewer(palette = \"Set1\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "df65d3f1",
   "metadata": {},
   "source": [
    "### 1.4. Use \"count2d\" statistical transformation"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "73a8987c",
   "metadata": {},
   "source": [
    "`geomPie()` uses `count2d` stat by default. \n",
    "It allows to make a slice sizes proportional to the number of cases in each group  (or if the weight aesthetic is supplied, the sum of the weights). Also `count2d` provides variables for proportion ('..prop..') and proportion in percent ('..proppct..'). "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e9d823c8",
   "metadata": {},
   "source": [
    "Using `layerTooltips()` prepare the information for tooltips by adding the variables provided by 'count2d':"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "1d183b4d",
   "metadata": {},
   "outputs": [],
   "source": [
    "val tooltipContent = layerTooltips()\n",
    "                        .line(\"count|@{..count..} (@{..prop..})\")\n",
    "                        .line(\"total|@{..sum..}\")\n",
    "                        .format(\"..prop..\", \".0%\")\n",
    "                        .format(\"..count..\", \".1f\")\n",
    "                        .format(\"..sum..\", \".1f\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2bce5820",
   "metadata": {},
   "source": [
    "Apply 'count2d' to get slices proportional to the number of cases."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "ab7010dc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"mLAR4M\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"mapping\":{\n",
       "},\n",
       "\"data\":{\n",
       "},\n",
       "\"ggsize\":{\n",
       "\"width\":400.0,\n",
       "\"height\":250.0\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"fill\",\n",
       "\"scale_mapper_kind\":\"color_brewer\",\n",
       "\"palette\":\"Set1\"\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"hole\":0.5,\n",
       "\"mapping\":{\n",
       "\"fill\":\"name\"\n",
       "},\n",
       "\"stat\":\"count2d\",\n",
       "\"size\":20.0,\n",
       "\"stroke_color\":\"white\",\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"pie\",\n",
       "\"stroke\":1.0,\n",
       "\"tooltips\":{\n",
       "\"lines\":[\"count|@{..count..} (@{..prop..})\",\"total|@{..sum..}\"],\n",
       "\"formats\":[{\n",
       "\"field\":\"..prop..\",\n",
       "\"format\":\".0%\"\n",
       "},{\n",
       "\"field\":\"..count..\",\n",
       "\"format\":\".1f\"\n",
       "},{\n",
       "\"field\":\"..sum..\",\n",
       "\"format\":\".1f\"\n",
       "}]\n",
       "},\n",
       "\"labels\":{\n",
       "\"lines\":[\"@name\"],\n",
       "\"annotation_size\":16\n",
       "},\n",
       "\"data\":{\n",
       "\"..sum..\":[5.0,5.0,5.0,5.0],\n",
       "\"..x..\":[0.0,0.0,0.0,0.0],\n",
       "\"..count..\":[1.0,2.0,1.0,1.0],\n",
       "\"..y..\":[0.0,0.0,0.0,0.0],\n",
       "\"name\":[\"a\",\"b\",\"c\",\"d\"],\n",
       "\"..prop..\":[0.2,0.4,0.2,0.2]\n",
       "}\n",
       "}],\n",
       "\"theme\":{\n",
       "\"axis\":{\n",
       "\"blank\":true\n",
       "},\n",
       "\"line\":{\n",
       "\"blank\":true\n",
       "},\n",
       "\"legend_position\":\"none\"\n",
       "}\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"mLAR4M\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();    \n",
       "   </script>"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p +\n",
    "    geomPie(\n",
    "        size = 20, stroke = 1, strokeColor = \"white\", hole = 0.5,\n",
    "        labels = layerLabels().line(\"@name\").size(16),\n",
    "        tooltips = tooltipContent\n",
    "    ) { fill = \"name\" } +\n",
    "    blankTheme + \n",
    "    theme().legendPositionNone() +\n",
    "    scaleFillBrewer(palette = \"Set1\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "32d1cdc0",
   "metadata": {},
   "source": [
    "Compute weighted sum instead of simple count with aesthetic `weight`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "77f81cce",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"U5TgXB\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"mapping\":{\n",
       "},\n",
       "\"data\":{\n",
       "},\n",
       "\"ggsize\":{\n",
       "\"width\":400.0,\n",
       "\"height\":250.0\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"fill\",\n",
       "\"scale_mapper_kind\":\"color_brewer\",\n",
       "\"palette\":\"Set1\"\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"hole\":0.5,\n",
       "\"mapping\":{\n",
       "\"fill\":\"name\",\n",
       "\"weight\":\"value\"\n",
       "},\n",
       "\"stat\":\"count2d\",\n",
       "\"size\":20.0,\n",
       "\"stroke_color\":\"white\",\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"pie\",\n",
       "\"stroke\":1.0,\n",
       "\"tooltips\":{\n",
       "\"lines\":[\"count|@{..count..} (@{..prop..})\",\"total|@{..sum..}\"],\n",
       "\"formats\":[{\n",
       "\"field\":\"..prop..\",\n",
       "\"format\":\".0%\"\n",
       "},{\n",
       "\"field\":\"..count..\",\n",
       "\"format\":\".1f\"\n",
       "},{\n",
       "\"field\":\"..sum..\",\n",
       "\"format\":\".1f\"\n",
       "}]\n",
       "},\n",
       "\"labels\":{\n",
       "\"lines\":[\"@name\"],\n",
       "\"annotation_size\":16\n",
       "},\n",
       "\"data\":{\n",
       "\"..sum..\":[210.0,210.0,210.0,210.0],\n",
       "\"..x..\":[0.0,0.0,0.0,0.0],\n",
       "\"..count..\":[40.0,110.0,10.0,50.0],\n",
       "\"..y..\":[0.0,0.0,0.0,0.0],\n",
       "\"name\":[\"a\",\"b\",\"c\",\"d\"],\n",
       "\"..prop..\":[0.19047619047619047,0.5238095238095238,0.047619047619047616,0.23809523809523808]\n",
       "}\n",
       "}],\n",
       "\"theme\":{\n",
       "\"axis\":{\n",
       "\"blank\":true\n",
       "},\n",
       "\"line\":{\n",
       "\"blank\":true\n",
       "},\n",
       "\"legend_position\":\"none\"\n",
       "}\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"U5TgXB\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();    \n",
       "   </script>"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p +\n",
    "    geomPie(\n",
    "        size = 20, stroke = 1, strokeColor = \"white\", hole = 0.5,\n",
    "        labels = layerLabels().line(\"@name\").size(16),\n",
    "        tooltips = tooltipContent\n",
    "    ) { fill = \"name\"; weight = \"value\" } +\n",
    "    blankTheme + \n",
    "    theme().legendPositionNone() +\n",
    "    scaleFillBrewer(palette = \"Set1\")    "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4772e96d",
   "metadata": {},
   "source": [
    "Order sectors by count.\n",
    "\n",
    "The following ordering rule is used for the pie chart: the first slice goes to the left of 12 o'clock and others go clockwise."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "90a172ad",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"WH3zXs\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"mapping\":{\n",
       "},\n",
       "\"data\":{\n",
       "},\n",
       "\"ggsize\":{\n",
       "\"width\":400.0,\n",
       "\"height\":250.0\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"fill\",\n",
       "\"scale_mapper_kind\":\"color_brewer\",\n",
       "\"palette\":\"Set1\"\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"hole\":0.5,\n",
       "\"mapping\":{\n",
       "\"fill\":\"@as_discrete@name\",\n",
       "\"weight\":\"value\"\n",
       "},\n",
       "\"stat\":\"count2d\",\n",
       "\"size\":20.0,\n",
       "\"stroke_color\":\"white\",\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"pie\",\n",
       "\"stroke\":1.0,\n",
       "\"data_meta\":{\n",
       "\"mapping_annotations\":[{\n",
       "\"aes\":\"fill\",\n",
       "\"annotation\":\"as_discrete\",\n",
       "\"parameters\":{\n",
       "\"label\":\"name\",\n",
       "\"order_by\":\"..count..\"\n",
       "}\n",
       "}]\n",
       "},\n",
       "\"tooltips\":{\n",
       "\"lines\":[\"count|@{..count..} (@{..prop..})\",\"total|@{..sum..}\"],\n",
       "\"formats\":[{\n",
       "\"field\":\"..prop..\",\n",
       "\"format\":\".0%\"\n",
       "},{\n",
       "\"field\":\"..count..\",\n",
       "\"format\":\".1f\"\n",
       "},{\n",
       "\"field\":\"..sum..\",\n",
       "\"format\":\".1f\"\n",
       "}]\n",
       "},\n",
       "\"labels\":{\n",
       "\"lines\":[\"@name\"],\n",
       "\"annotation_size\":16\n",
       "},\n",
       "\"data\":{\n",
       "\"..sum..\":[210.0,210.0,210.0,210.0],\n",
       "\"..x..\":[0.0,0.0,0.0,0.0],\n",
       "\"..count..\":[110.0,50.0,40.0,10.0],\n",
       "\"..y..\":[0.0,0.0,0.0,0.0],\n",
       "\"name\":[\"b\",\"d\",\"a\",\"c\"],\n",
       "\"@as_discrete@name\":[\"b\",\"d\",\"a\",\"c\"],\n",
       "\"..prop..\":[0.5238095238095238,0.23809523809523808,0.19047619047619047,0.047619047619047616]\n",
       "}\n",
       "}],\n",
       "\"theme\":{\n",
       "\"axis\":{\n",
       "\"blank\":true\n",
       "},\n",
       "\"line\":{\n",
       "\"blank\":true\n",
       "},\n",
       "\"legend_position\":\"none\"\n",
       "}\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"WH3zXs\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();    \n",
       "   </script>"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p +\n",
    "    geomPie(\n",
    "        size = 20, stroke = 1, strokeColor = \"white\", hole = 0.5,\n",
    "        labels = layerLabels().line(\"@name\").size(16),\n",
    "        tooltips = tooltipContent\n",
    "    ) { fill = asDiscrete(\"name\", orderBy = \"..count..\"); weight = \"value\" } +\n",
    "    blankTheme + \n",
    "    theme().legendPositionNone() +\n",
    "    scaleFillBrewer(palette = \"Set1\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2b506543",
   "metadata": {},
   "source": [
    "## 2. Pie size depending on data"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "40def630",
   "metadata": {},
   "source": [
    "Make the size of the pie chart dependent on the data: map total count ('..sum..' variable) to the `size`.\n",
    "\n",
    "Note that it has its own special representation of the size in the legend."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "407aa42e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"KiRedV\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"mapping\":{\n",
       "},\n",
       "\"data\":{\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"x\",\n",
       "\"limits\":[0.5,2.5]\n",
       "},{\n",
       "\"aesthetic\":\"y\",\n",
       "\"limits\":[0.5,2.5]\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"hole\":0.3,\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\",\n",
       "\"size\":\"..sum..\",\n",
       "\"fill\":\"@as_discrete@n\",\n",
       "\"weight\":\"s\"\n",
       "},\n",
       "\"stat\":\"count2d\",\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"pie\",\n",
       "\"data_meta\":{\n",
       "\"mapping_annotations\":[{\n",
       "\"aes\":\"fill\",\n",
       "\"annotation\":\"as_discrete\",\n",
       "\"parameters\":{\n",
       "\"label\":\"n\",\n",
       "\"order_by\":\"..count..\",\n",
       "\"order\":-1\n",
       "}\n",
       "}]\n",
       "},\n",
       "\"tooltips\":{\n",
       "\"lines\":[\"count|@{..count..} (@{..prop..})\",\"total|@{..sum..}\"],\n",
       "\"formats\":[{\n",
       "\"field\":\"..prop..\",\n",
       "\"format\":\".0%\"\n",
       "},{\n",
       "\"field\":\"..count..\",\n",
       "\"format\":\".1f\"\n",
       "},{\n",
       "\"field\":\"..sum..\",\n",
       "\"format\":\".1f\"\n",
       "}]\n",
       "},\n",
       "\"data\":{\n",
       "\"..sum..\":[11.0,4.0,7.0,11.0,7.0,11.0,4.0,7.0],\n",
       "\"..count..\":[9.0,1.0,3.0,1.0,3.0,1.0,3.0,1.0],\n",
       "\"@as_discrete@n\":[\"a\",\"a\",\"a\",\"c\",\"c\",\"b\",\"b\",\"b\"],\n",
       "\"x\":[1.0,1.5,2.0,1.0,2.0,1.0,1.5,2.0],\n",
       "\"y\":[1.0,2.0,1.5,1.0,1.5,1.0,2.0,1.5],\n",
       "\"..prop..\":[0.8181818181818182,0.25,0.42857142857142855,0.09090909090909091,0.42857142857142855,0.09090909090909091,0.75,0.14285714285714285]\n",
       "}\n",
       "}]\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"KiRedV\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();    \n",
       "   </script>"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "val data2 = mapOf(\n",
    "    \"x\" to listOf(1, 1, 1, 1, 1, 1.5, 1.5,   2,   2,   2),\n",
    "    \"y\" to listOf(1, 1, 1, 1, 1,   2,   2, 1.5, 1.5, 1.5),\n",
    "    \"s\" to listOf(3, 1, 2, 1, 4,   1,   3,   3,   3,  1),\n",
    "    \"n\" to listOf('a', 'b', 'a', 'c', 'a',  'a', 'b', 'c', 'a',  'b')\n",
    ")\n",
    "\n",
    "\n",
    "letsPlot(data2) +\n",
    "    geomPie(hole = 0.3, tooltips = tooltipContent) { \n",
    "        x = \"x\"\n",
    "        y = \"y\"\n",
    "        fill = asDiscrete(\"n\", orderBy = \"..count..\", order = -1)\n",
    "        weight = \"s\"\n",
    "        size = \"..sum..\"\n",
    "    } +\n",
    "    xlim(0.5 to 2.5) + ylim(0.5 to 2.5)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fa9e9195",
   "metadata": {},
   "source": [
    "Mapping `fill` and `size` to the same variable:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "fc4c8b13",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"38QXLG\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"mapping\":{\n",
       "},\n",
       "\"data\":{\n",
       "\"s\":[1.0,2.0,3.0],\n",
       "\"n\":[\"a\",\"b\",\"c\"]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"slice\":\"s\",\n",
       "\"size\":\"n\",\n",
       "\"fill\":\"n\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"pie\",\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"theme\":{\n",
       "\"axis\":{\n",
       "\"blank\":true\n",
       "},\n",
       "\"line\":{\n",
       "\"blank\":true\n",
       "}\n",
       "}\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"38QXLG\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();    \n",
       "   </script>"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "letsPlot(data = mapOf(\"n\" to listOf(\"a\", \"b\", \"c\"), \"s\" to listOf(1, 2, 3))) + \n",
    "    geomPie(stat = Stat.identity) { fill = \"n\"; slice = \"s\"; size = \"n\" } +\n",
    "    blankTheme"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "06bd6ffc",
   "metadata": {},
   "source": [
    "## 3. Explode"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5f244752",
   "metadata": {},
   "source": [
    "Use values to explode slices away from their center point, detaching it from the main pie."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "56e5d9b3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"eWb4kj\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"mapping\":{\n",
       "},\n",
       "\"data\":{\n",
       "\"explode\":[0.0,0.0,0.0,0.1,0.1,0.2,0.3,0.4,0.6],\n",
       "\"name\":[\"20-50 km\",\"50-75 km\",\"10-20 km\",\"75-100 km\",\"3-5 km\",\"7-10 km\",\"5-7 km\",\">100 km\",\"2-3 km\"],\n",
       "\"count\":[1109.0,696.0,353.0,192.0,168.0,86.0,74.0,65.0,53.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"fill\",\n",
       "\"scale_mapper_kind\":\"color_gradient\",\n",
       "\"high\":\"light_green\",\n",
       "\"low\":\"dark_blue\"\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"slice\":\"count\",\n",
       "\"explode\":\"explode\",\n",
       "\"fill\":\"name\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":20.0,\n",
       "\"stroke_color\":\"black\",\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"pie\",\n",
       "\"stroke\":1.0,\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"theme\":{\n",
       "\"axis\":{\n",
       "\"blank\":true\n",
       "},\n",
       "\"line\":{\n",
       "\"blank\":true\n",
       "}\n",
       "}\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"eWb4kj\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();    \n",
       "   </script>"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "val length = mapOf(\n",
    "  \"name\" to listOf(\"20-50 km\", \"50-75 km\", \"10-20 km\", \"75-100 km\", \"3-5 km\", \"7-10 km\", \"5-7 km\", \">100 km\", \"2-3 km\"),\n",
    "  \"count\" to listOf(1109, 696, 353, 192, 168, 86, 74, 65, 53),\n",
    "  \"explode\" to listOf(0, 0, 0, 0.1, 0.1, 0.2, 0.3, 0.4, 0.6)\n",
    ")\n",
    "\n",
    "ggplot(length) + blankTheme +\n",
    "    geomPie(stat = Stat.identity, stroke = 1, strokeColor = \"black\", size = 20) {\n",
    "        fill = \"name\"; slice = \"count\"; explode = \"explode\"\n",
    "    } +\n",
    "    scaleFillGradient(low = \"dark_blue\", high = \"light_green\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "5953f8aa",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"wYmPw5\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"kind\":\"ggbunch\",\n",
       "\"items\":[{\n",
       "\"x\":0,\n",
       "\"width\":400,\n",
       "\"y\":0,\n",
       "\"feature_spec\":{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"data\":{\n",
       "\"slice\":[35.0,25.0,25.0,15.0],\n",
       "\"explode\":[0.1,0.0,0.0,0.0],\n",
       "\"label\":[\"Apples\",\"Bananas\",\"Cherries\",\"Dates\"]\n",
       "},\n",
       "\"ggsize\":{\n",
       "\"width\":400.0,\n",
       "\"height\":250.0\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"fill\",\n",
       "\"scale_mapper_kind\":\"color_brewer\",\n",
       "\"palette\":\"Set1\"\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"slice\":\"slice\",\n",
       "\"explode\":\"explode\",\n",
       "\"fill\":\"label\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":18.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"pie\",\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"theme\":{\n",
       "\"axis\":{\n",
       "\"blank\":true\n",
       "},\n",
       "\"line\":{\n",
       "\"blank\":true\n",
       "},\n",
       "\"legend_position\":\"none\"\n",
       "}\n",
       "},\n",
       "\"height\":250\n",
       "},{\n",
       "\"x\":400,\n",
       "\"width\":400,\n",
       "\"y\":0,\n",
       "\"feature_spec\":{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"data\":{\n",
       "\"slice\":[35.0,25.0,25.0,15.0],\n",
       "\"explode\":[0.1,0.0,0.0,0.0],\n",
       "\"label\":[\"Apples\",\"Bananas\",\"Cherries\",\"Dates\"]\n",
       "},\n",
       "\"ggsize\":{\n",
       "\"width\":400.0,\n",
       "\"height\":250.0\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"fill\",\n",
       "\"scale_mapper_kind\":\"color_brewer\",\n",
       "\"palette\":\"Set1\"\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"hole\":0.8,\n",
       "\"mapping\":{\n",
       "\"slice\":\"slice\",\n",
       "\"explode\":\"explode\",\n",
       "\"fill\":\"label\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":18.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"pie\",\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"theme\":{\n",
       "\"axis\":{\n",
       "\"blank\":true\n",
       "},\n",
       "\"line\":{\n",
       "\"blank\":true\n",
       "}\n",
       "}\n",
       "},\n",
       "\"height\":250\n",
       "}]\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"wYmPw5\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();    \n",
       "   </script>"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "val calories = mapOf(\n",
    "    \"slice\" to listOf(35, 25, 25, 15),\n",
    "    \"label\" to listOf(\"Apples\", \"Bananas\", \"Cherries\", \"Dates\"),\n",
    "    \"explode\" to listOf(0.1, 0, 0, 0)\n",
    ")\n",
    "\n",
    "val p4 = ggplot(calories) +\n",
    "    blankTheme +\n",
    "    scaleFillBrewer(palette=\"Set1\") +\n",
    "    ggsize(w, h)\n",
    "\n",
    "gggrid(plots = listOf(\n",
    "    p4 + geomPie(stat = Stat.identity, size = 18) {\n",
    "        fill = \"label\"; slice = \"slice\"; explode = \"explode\"\n",
    "    } + theme().legendPositionNone(),\n",
    "    p4 + geomPie(stat = Stat.identity, size = 18, hole = 0.8) {\n",
    "        fill = \"label\"; slice = \"slice\"; explode = \"explode\"\n",
    "    }),\n",
    "       ncol = 2,\n",
    "       cellWidth = w,\n",
    "       cellHeight = h\n",
    ")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Kotlin",
   "language": "kotlin",
   "name": "kotlin"
  },
  "language_info": {
   "codemirror_mode": "text/x-kotlin",
   "file_extension": ".kt",
   "mimetype": "text/x-kotlin",
   "name": "kotlin",
   "nbconvert_exporter": "",
   "pygments_lexer": "kotlin",
   "version": "1.8.20"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
